<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script type="importmap">
    {
        "imports": {
            "three": "./build/three.module.js",
            "three/addons/": "./examples/jsm/"
        }
    }
</script>
<script type="module">
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
    import Stats from 'three/addons/libs/stats.module.js';

    const width = window.innerWidth;
    const height = window.innerHeight;

    // 创建场景 相机 渲染器 
    const scene = new THREE.Scene()

    // 设置渲染器锯齿属性.antialias的值可以直接在参数中设置，也可通过渲染器对象属性设置。
    const renderer = new THREE.WebGLRenderer({
        antialias: true,  // 渲染模糊时可以开启
    });
    // 或
    // renderer.antialias = true;


    renderer.setSize(width, height)
    renderer.setClearColor(0x444444, 1); //设置背景颜色


    // 如果你遇到你的canvas画布输出模糊问题，注意设置 renderer.setPixelRatio(window.devicePixelRatio)。
    console.log('查看当前屏幕设备像素比', window.devicePixelRatio);
    renderer.setPixelRatio(window.devicePixelRatio);
    // 不同硬件设备的屏幕的设备像素比window.devicePixelRatio值可能不同

    const camera = new THREE.PerspectiveCamera(30, width / height, 1, 3000);
    camera.position.set(400, 400, 400);
    camera.lookAt(0, 0, 0);

    // 添加辅助坐标轴
    const axesHelper = new THREE.AxesHelper(150);
    scene.add(axesHelper)

    // 创建几何体
    const geometry = new THREE.BoxGeometry(100, 100, 100);
    // 设置渲染器锯齿属性.antialias的值可以直接在参数中设置，也可通过渲染器对象属性设置。
    const material = new THREE.MeshBasicMaterial({
        color: 0x00ffff,
        transparent: true,//开启透明
        opacity: 0.5,//设置透明度
        // antialias: true,
    })
    const mesh = new THREE.Mesh(geometry, material)
    mesh.position.set(0, 0, 0);
    scene.add(mesh)

    // 添加
    scene.add(mesh)
    document.body.appendChild(renderer.domElement);
    renderer.render(scene, camera)
</script>

</html>